require 'parser/SymFunction.rb'

class EyeFunction < SymFunction
    
    # Parameters are already checked, here we compare types
    def initialize
        @name = 'eye'
        @type = 'mat'
        @param_types = ['num']
    end
 
    # Executes de function contained in 'self'
    # === Parameters
    # * params -> True value of the parameters that the function will be evaluated with
    # * func_table -> Symbol table of the declared functions
    # === Return value
    # nil if executed with success or an error message
    def execute params, func_table
      if params[0] < 1
        return "Tratando de crear matriz identidad con número menor a 1 '#{params[0]}'"
      end
      lvec = []
      for i in (0..params[0]-1)
        v = []
        for j in (0..params[0]-1)
          v.push(i == j ? 1 : 0)
        end
        vec = Vector.new v
        lvec.push(vec)
      end
      @returned = Matrix.new lvec
      nil
    end
end
